/*
 * @Descripttion: 
 * @version: 
 * @Author: weni09
 * @Date: 2021-03-22 08:44:48
 * @LastEditors: weni09
 * @LastEditTime: 2021-06-15 11:00:09
 * @FilePath: \icoder-frontend\admin\vue.config.js
 */
const CompressionPlugin = require('compression-webpack-plugin');
// const path = require( 'path' );
const productionGzipExtensions = ['html', 'js', 'css'];

module.exports = {
  runtimeCompiler: true,
  productionSourceMap: false,
  publicPath: process.env.BASE_URL || '/',
  lintOnSave: false,
  css: {
    extract: true
  },

  configureWebpack: {
    plugins: [
    // 代码压缩
    // ..................
    // gzip压缩
      new CompressionPlugin({
        filename: '[path].gz[query]',
        algorithm: 'gzip',
        test: new RegExp(
            '\\.(' + productionGzipExtensions.join('|') + ')$'
        ),
        threshold: 10240, // 只有大小大于该值的资源会被处理 10240
        minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
        deleteOriginalAssets: false // 删除原文件
    })
  ],
    // No need for splitting
    optimization: {
      // splitChunks: {
      //   chunks: 'all'
      // }
      splitChunks: {
        cacheGroups: {
            vendor: {
                chunks: 'all',
                test: /node_modules/,
                name: 'vendor',
                minChunks: 1,
                maxInitialRequests: 5,
                minSize: 0,
                priority: 100
            },
            common: {
                chunks: 'all',
                test: /[\\/]src[\\/]js[\\/]/,
                name: 'common',
                minChunks: 2,
                maxInitialRequests: 5,
                minSize: 0,
                priority: 60
            },
            styles: {
                name: 'styles',
                test: /\.(sa|sc|c)ss$/,
                chunks: 'all',
                enforce: true
            },
            runtimeChunk: {
                name: 'manifest'
            }
        }
    }
    },

  },

  chainWebpack(config) {
    // config.plugins.delete('prefetch');
   },

  pluginOptions: {
    i18n: {
      locale: 'en',
      fallbackLocale: 'en',
      localeDir: 'locales',
      enableInSFC: true
    }
  }
}
